#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import random
import scipy.special as sps

def normal_distribution():
    mu, sigma = 16, 4 # mean and standard deviation
    s = np.random.normal(mu, sigma, 1000)
    days = random.sample(s, 1000)
    for i in days:
        print i
    print max(days)
    print min(days)
    count, bins, ignored = plt.hist(s, 30, normed=True)
    plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
             np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
            linewidth=2, color='r')
    plt.title("The Number of Days of the Page's Updating")
    plt.show()

def gamma_distribution():
    shape, scale = 2., 2. # mean and dispersion
    s = np.random.gamma(shape, scale, 875713)

    count, bins, ignored = plt.hist(s, 50, normed=True)
    y = bins**(shape-1)*(np.exp(-bins/scale) /
                     (sps.gamma(shape)*scale**shape))
    plt.plot(bins, y, linewidth=2, color='r')
    plt.show()

def his():
    s = [1,2,3,3,3,3,4,5,2,0,3,2,1]
    
    plt.gca().set_xlim([0, max(s)+1])
    plt.axis([100000, 200000, 0, 10])
    n, bins, patches = plt.hist(s, bins=[0, 10, 20, 30, 40, 50, 100])
    plt.show()
    
def main():
#     normal_distribution()
#     gamma_distribution()
    his()
    
if __name__ == '__main__':
    main()
